#ifndef PDF_H
#define PDF_H

#include "onb.h"
#include "Hit/hittable_list.h"


class pdf {
public:
    virtual ~pdf() {}

    virtual double value(const vec3& direction) const = 0;
    virtual vec3 generate() const = 0;// 生成一个随机方向
};

class sphere_pdf : public pdf {
public:
    sphere_pdf() {}

    double value(const vec3& direction) const override;

    vec3 generate() const override;
};

class cosine_pdf : public pdf {
public:
    cosine_pdf(const vec3& w) : uvw(w) {}

    double value(const vec3& direction) const override;

    vec3 generate() const override;

private:
    onb uvw;
};

class hittable_pdf : public pdf {
public:
    hittable_pdf(const hittable& objects, const point3& origin)
        : objects(objects), origin(origin)
    {
    }

    double value(const vec3& direction) const override;

    vec3 generate() const override;
private:
    const hittable& objects;// 需要击中的object
    point3 origin;// 发射光线的原点
};

class mixture_pdf : public pdf {
public:
    mixture_pdf(shared_ptr<pdf> p0, shared_ptr<pdf> p1) {
        p[0] = p0;
        p[1] = p1;
    }

    double value(const vec3& direction) const override {
        return 0.5 * p[0]->value(direction) + 0.5 * p[1]->value(direction);
    }

    vec3 generate() const override {
        if (random_double() < 0.5)
            return p[0]->generate();
        else
            return p[1]->generate();
    }

private:
    shared_ptr<pdf> p[2];
};

#endif